<?php
namespace Apps\Front\Controllers;
use Apps\Front\Controllers\ControllerBase;
use Apps\Model\Bank;
use Apps\Model\Pay;
use Apps\Model\User;

class UserinfoController extends ControllerBase{

	public function initialize(){
       $this->session();
	}

    public function indexAction(){
       $user_id=$this->session->get('operator')->id;
       $user=User::findFirst("id='$user_id'");
       $user_money=$user->money;
       $this->view->setvar('user_money',$user_money);
    }

    public  function favoriteAction(){
    	
    }
    public  function rmbaccountAction(){
      $user_id=$this->session->get('operator')->id;
      $user=User::findFirst("id=$user_id");
      $user_money=$user->money;

      $payinfos=Pay::find("uid=$user_id and state=1 order by time desc");
      $undefinepays=Pay::find("uid=$user_id and state=0 order by time desc");
      $this->view->setvar('user_money',$user_money);
      $this->view->setvar('payinfos',$payinfos);
      $this->view->setvar('undefinepays',$undefinepays);
    	
    }
    public  function payAction(){
    	$banks=Bank::find();
    	$this->view->setvar('banks',$banks);
    }

    public  function payokAction(){

    	$this->view->disable();
    	$bankname=$this->request->getPost('pay_bank','string');
    	$paymoney=$this->request->getPost('paymoney','float');
    	$message=$this->request->getPost('remark','string');
    	if($paymoney==0){
    		$paymoney=$paymoney=$this->request->getPost('pay_qita','float');
    	}
        if ($this->request->hasFiles() == true) {
            foreach ($this->request->getUploadedFiles() as $file) {
                $picname= $file->getName();
            }
        }
        date_default_timezone_set('Asia/Shanghai');
        $time=time();
        $paytime=date("Y-m-d,h:i:s",$time);
        $uid=$this ->session ->get('operator')->id;
        $tradenumber=date("Ymd",$time).mt_rand(100000,999999);
        $map=new pay();
        $map -> uid = $uid;
        $map -> bank = $bankname;
        $map -> money = $paymoney;
        $map -> pic = $picname;
        $map -> time = $paytime;
        $map -> state = 0;
        $map -> message = $message;
        $map -> tradenumber = $tradenumber;
        $map -> save();
        $this->jump("Userinfo/payconfirm",'充值请求已经提交给管理员');
    }
}
